package uiHelpers;

import com.intouchtv.ari.NabDemoView;

import android.graphics.Rect;
import android.util.TypedValue;
import android.widget.AbsoluteLayout;
import android.widget.Button;


@SuppressWarnings("deprecation")
public class ButtonAdder implements Runnable {
	NabDemoView view;
	final int movieId;
	final int id;
	final Rect location;
	final int color;
	boolean isVisible;
	final String text;
	final boolean isShowClickEffect;
	int clickEffectColor;
	AbsoluteLayout layout;
	
	public ButtonAdder(NabDemoView _view, final int _movieId,final int _id, final Rect _location, final int _color,
			boolean _isVisible, final String _text, final boolean _isShowClickEffect,
			int _clickEffectColor, AbsoluteLayout _layout)
	{
		view = _view;
		movieId = _movieId;
		id = _id;
		location = _location;
		color = _color;
		isVisible = _isVisible;
		text = _text;
		isShowClickEffect = _isShowClickEffect;
		layout = _layout;
	}
	
	@Override
	public void run() {
		Button btn = new Button(view); 
		btn.setText(text);
		btn.setTextSize(TypedValue.COMPLEX_UNIT_DIP,14);
		int btnWidth = location.width();
		if (btnWidth < text.length() * 15)
			btnWidth = text.length() * 15;
		
		btn.setLayoutParams(new AbsoluteLayout.LayoutParams(btnWidth,location.height(),
				location.left,location.top));
		try{
			layout.addView(btn, btn.getLayoutParams());
		}
		catch (Exception e) {
			view.RaiseErrorMsg("Button Adder");
		}
		layout.bringChildToFront(btn);
		
		view.addViewToDataStructure(movieId, id, btn);

		btn.setOnClickListener(view.controller.getEventManager());
		
		layout.postInvalidate();
	}
}

